package com.tjetc.controller;

import com.tjetc.domain.FollowHospital;
import com.tjetc.domain.Hospital;
import com.tjetc.service.FollowHospitalService;
import com.tjetc.service.impl.FollowHospitalServiceImpl;
import com.tjetc.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (follow_hospital)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/followHospital")
public class FollowHospitalController {
    /**
     * 服务对象
     */
    @Resource
    private FollowHospitalService followHospitalService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public FollowHospital selectOne(Integer id) {
        return followHospitalService.selectByPrimaryKey(id);
    }
    @GetMapping("isFollow")
    public Result isFollow(@RequestParam("phone") String phone, @RequestParam("hid") Integer hid) {
        return followHospitalService.isFollow(phone,hid);
    }
    @GetMapping("follow")
    public Result follow(@RequestParam("phone") String phone, @RequestParam("hid") Integer hid) {
        return followHospitalService.follow(phone,hid);
    }
    @GetMapping("cancelFollow")
    public Result cancelFollow(@RequestParam("phone") String phone, @RequestParam("hid") Integer hid) {
        return followHospitalService.cancelFollow(phone,hid);
    }
    @GetMapping("selNameAndIcon")
    public List<Hospital> selNameAndIcon(@RequestParam("uid") Integer uid) {
        return followHospitalService.selNameAndIcon(uid);
    }
    @GetMapping("selByUid")
    public List<Hospital> selByUid(@RequestParam("uid") Integer uid) {
        return followHospitalService.selByUid(uid);
    }

    @GetMapping("deleteByPrimaryKey")
    public Result deleteByPrimaryKey(@RequestParam("hid") Integer hid, @RequestParam("uid") Integer uid) {
        return followHospitalService.deleteByHidAndUid(hid,uid)==1?Result.ok():Result.fail("失败");
    }

    @RequestMapping("getFanCount")
    public Result getFanCount(@RequestParam("hospitalName") String hospitalName)  {
        return followHospitalService.getFanCount(hospitalName);
    }
}
